package main;

import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.ArrayList;

import junit.framework.TestCase;

public class TestCollisonDetector extends TestCase {

    public void testAddObject() {
        CollisonDetector detector = new CollisonDetector();
        Brick aBrick = new Brick(0, 0, 1, 1);
        assertEquals(0, detector.size());
        int colliderNum = detector.addObject(aBrick);
        assertEquals(1, colliderNum);
    }

    public void testClearAllObjects() {
        CollisonDetector detector = new CollisonDetector();
        Brick aBrick = new Brick(0, 0, 1, 1);
        int colliderNum = detector.addObject(aBrick);
        assertEquals(colliderNum, 1);
        detector.clearAllObjects();
    }

    public void testDoCollision() {
        CollisonDetector detector = new CollisonDetector();
        Brick brickA = new Brick(0, 0, 1, 1);
        brickA.setSpeed(new Point2D.Double(1, 1));
        Brick brickB = new Brick(0.5, 0.5, 1, 1);
        detector.addObject(brickA);
        detector.addObject(brickB);
        ArrayList<Pair> resultArrayList = detector.doCollision();
        assertEquals(1, resultArrayList.size());
    }

    public void testUpdateAllPosition() {
        CollisonDetector detector = new CollisonDetector();
        //the center of brickA is (1,1)
        Brick brickA = new Brick(0, 0, 2, 2);
        brickA.setSpeed(new Point2D.Double(1, 0));
        detector.addObject(brickA);
        detector.updateAllPosition(1);
        assertEquals(true, brickA.getPosition()
                .equals(new Point2D.Double(2, 1)));
    }

    public void testRemoveObject() {
        CollisonDetector detector = new CollisonDetector();
        //the center of brickA is (1,1)
        Brick brickA = new Brick(0, 0, 2, 2);
        detector.addObject(brickA);
        assertEquals(1, detector.size());
        detector.removeObject(brickA);
        assertEquals(0, detector.size());
    }

}
